<?php
/**
 * The template for displaying Category pages
 *
 * Used to display archive-type pages for posts in a category.
 *
 * @link http://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */

get_header(); ?>
<?php

$postsSticky = get_posts(array('post__in'=>get_option('sticky_posts'),'category'=>$cat));

//$posts = get_posts(array('post__not_in'=>get_option('sticky_posts'),'category'=>$cat));
global $posts;

//$posts = get_posts(array('post__not_in'=>get_option('sticky_posts'),'category'=>$cat));
//$cat_posts = array_merge($postsSticky,$cat_nonSticky);

 
//$posts = get_posts();

?>


	<section id="primary" class="site-content">
		<div id="content" role="main" class="<?php if (is_single())  echo "single"; else echo "notsingle"; ?>" >
		<?php 
		if($postsSticky){
		?>
		<div class="recomment-box">
			<ul class="recomment-list">
			<?php 
			//for($i=0; $i<count($posts); $i++){
			$i=0;
			foreach($postsSticky as $post){
				//$post = $posts[$i];
				$img = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );
				if(!$img || $img =='')
					$img = get_first_image($post->post_content);
			?>
				<li><div class="recomment-main">
				<div class="rimg">
					<a href="<?php echo get_permalink($post->ID); ?>">
					<img src="<?php echo $img;?>" alt="" />
					</a>
				</div>
				<div class="rinfo">
					<a href="<?php echo get_permalink($post->ID); ?>">
					<h1 class="rtitle">
						<?php echo $post->post_title; ?>
					</h1>
					</a>
					<div class="rsnipet">
						<?php echo strip_tags(get_the_excerpt());?>
					</div>
				</div>
				<div class="clear"></div>
			</div></li>
			<?php 
			} ?>
			</ul>
			<div class="recomment-control">
				<a href="#next" class="prev"><</a>
				<a href="#next" class="next">></a>
			</div>
		</div>
		<?php
		}?>
		<div class="suggest-box">
		<?php 
			//for($i=0; $i<count($posts); $i++){
			$i=0;
			if($posts)
			foreach($posts as $post){
				//$post = $posts[$i];
				$img = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') );
				if(!$img || $img =='')
					$img = get_first_image($post->post_content);
			?>
			<li class="item">
				<a href="<?php echo get_permalink($post->ID); ?>">
				<img src="<?php echo $img;?>" alt="" />
				<h3><?php echo $post->post_title; ?></h3>
				</a>
			</li>
			<?php 
			unset($posts[$i]);
			$i++;
			if($i>3)
			break;
			} ?>
		</div>
		
		<div class="clear"></div>
		<?php if ( have_posts() ) : ?>
		<!--
			<header class="archive-header">
				<h1 class="archive-title hidethis"><?php single_cat_title(); ?></h1>

			<?php if ( category_description() ) : // Show an optional category description ?>
				<div class="archive-meta hidethis"><?php echo category_description(); ?></div>
			<?php endif; ?>
			</header><!-- .archive-header -->
			
			<?php
			/* Start the Loop */
			if($posts)
			foreach($posts as $post){
				 //setup_postdata($post);
				/* Include the post format-specific template for the content. If you want to
				 * this in a child theme then include a file called called content-___.php
				 * (where ___ is the post format) and that will be used instead.
				 */
				get_template_part( 'content', get_post_format() );

			}

			// twentytwelve_content_nav( 'nav-below' );
			
			?>
<?php wp_pagenavi(); ?>
		<?php else : ?>
			<?php get_template_part( 'content', 'none' ); ?>
		<?php endif; ?>

		</div><!-- #content -->
	</section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>